
import { put, takeEvery } from 'redux-saga/effects'
import apiType, {
    GET_WAREHOUSE_REFUND_PROCESS,
    GET_WAREHOUSE_REFUND_INFO
} from "@constants/ActionTypes";
import {getAxios, postAxios, putAxios, deleteAxios} from "@utils/api";

// 查看待处理退货单列表
export const getWarehouseRefundProcess = (params, callback) => ({
    type: apiType(GET_WAREHOUSE_REFUND_PROCESS).request,
    params,
    callback
})
// 查看退货单详情
export const getWarehouseRefundInfo = (params, callback) => ({
    type: apiType(GET_WAREHOUSE_REFUND_INFO).request,
    params,
    callback
})


const sagas = {
    * [apiType(GET_WAREHOUSE_REFUND_PROCESS).request]  ({ params, callback }) {
        try {
            const response = yield getAxios('/inventory/web/refund/processing', params)
            yield put({ type: apiType(GET_WAREHOUSE_REFUND_PROCESS).success, response });
            callback && callback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WAREHOUSE_REFUND_PROCESS).failure});
        }
    },
    * [apiType(GET_WAREHOUSE_REFUND_INFO).request]  ({ params, callback }) {
        try {
            const response = yield getAxios('/inventory/web/refund/info', params)
            yield put({ type: apiType(GET_WAREHOUSE_REFUND_INFO).success, response });
            callback && callback(response)
        } catch (e) {
            yield put({ type: apiType(GET_WAREHOUSE_REFUND_INFO).failure});
        }
    },

}
export default Object.keys(sagas).map(item => {
    return function * s() {
        yield takeEvery(item, function *(args) {
            try {
                yield sagas[item](args)
            } catch (e) {
                console.log(e)
            }
        })
    }
})